use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};

pub fn ipaddr_demo(){
    let v4 = IpAddr::V4(Ipv4Addr::new(127, 0,0, 1));
    let v6 = IpAddr::V6(Ipv6Addr::new(0, 0,0, 0,0,0,0, 1));

    println!("{}", v4);// 127.0.0.1
    println!("{}", v6); //::1
}

pub fn ipaddr_demo2(){
    let mut v4socket_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
    let mut v6socket_addr = SocketAddr::new(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 65535, 0, 1)), 8081);

    println!("{}", v4socket_addr); //127.0.0.1:8080
    println!("{}", v6socket_addr); //[::ffff:0.0.0.1]:8081

    v4socket_addr.set_ip(IpAddr::V4(Ipv4Addr::new(192, 168, 1, 1)));
    println!("{}", v4socket_addr); //192.168.1.1:8080
}